/*****Log*****/
clear
cd "C:\Users\Joshua\Dropbox\Work\Networks and Economic Perceptions\Data and Do Files"
	/*the above needs to be updated to where you have the data/do files*/
	
log using "Online Appendix C Output.smcl", replace
	/*the log file is in format .smcl, but can be read via txt editor*/

set more off

/***********************************************************************
************************************************************************
************************************************************************
This do file contains the needed to replicate Online Appendix C. We first 
investigate the characteristics of missing discussants. We then discuss
the role Independent and 3rd Party supporters in teh disagrement measures, 
before concluding with analyses of the 2006 and 2008 ANES surveys that
look at what happens when leaning partisans are counted as Independents vs
Leaners. 

For each survey, the code will load and clean the data at hand using the
commands included in the survey cleaning .do files and then do the 
analyses in question. For those wishing to use this to replicate the analyses, 
you will need to update the cd command below to point to where your data
and .do files are located. 

Also note that there are two STATA modules that need to be intalled: 
(1) esttab and (2) grc1leg. 

ssc install estout, replace
ssc install grc1leg, replace

Note: The analyses here were run using STATA 13. Users of STATA 15 
will likely get an error message when the esstab 
command below runs, specifically: 
	"equation / not found"
This is because of the "rename" function in the command seems to be 
broken in STATA 15. Deleting this line will fix matters. 


************************************************************************
************************************************************************
***********************************************************************/


/*********************************************************
**********************************************************
	Characteristics of missing discussants
**********************************************************
**********************************************************/

cd "C:\Users\Joshua\Dropbox\Work\Networks and Economic Perceptions\Data and Do Files"

/****************************************
*****************************************
		1992 CNEP
*****************************************
****************************************/	

*data cleaning*
clear
do "Data Cleaning - 1992 CNEP.do"
set more off


tab1 Z_US92_E_Disc2Part  Z_US92_E_Disc3Part  Z_US92_E_Disc4Part  Z_US92_E_Disc5Part 
		
recode Z_US92_E_Disc1Part Z_US92_E_Disc2Part  Z_US92_E_Disc3Part  Z_US92_E_Disc4Part  Z_US92_E_Disc5Part  ///
	 (-1 95=.) (0 8 9 = 1) (1 2 3 4 5 6 7 = 0), gen(d1_missing d2_missing d3_missing d4_missing d5_missing)
label def dmis 1 "Missing Pref" 0 "Not Missing Pref"
label values d1_missing d2_missing d3_missing d4_missing d5_missing dmis

foreach var in disc1_knowl disc1_freq d1_genagree {
	ttest `var', by(d1_missing)
	}

foreach var in disc2_knowl disc2_freq d2_genagree {
	ttest `var', by(d2_missing)
	}
	

foreach var in disc3_knowl disc3_freq d3_genagree {
	ttest `var', by(d3_missing)
	}
	
foreach var in disc4_knowl disc4_freq d4_genagree {
	ttest `var', by(d4_missing)
	}
	
	
foreach var in disc5_knowl disc5_freq d5_genagree {
	ttest `var', by(d5_missing)
	}	

	
/****************************************
*****************************************
		2000 ANES
*****************************************
****************************************/	

clear
do "Data Cleaning - 2000 ANES.do"
set more off

*Discussant Vote Choice
		foreach var in V001710 V001718 V001726 V001734 {
			tab `var'
		}
		*1 = Al Gore
		*3 = George Bush
		*5 = Some Other Candidate
		*7 = Didn't vote
		*8 = ineliglb to vote
		*98 = dk
		*99 = ref

recode V001710 V001718 V001726 V001734 (00 = . ) (1 3 =0) (5 7 8 98 99 = 1), ///
	gen(d1_missing d2_missing d3_missing d4_missing)
label def dmis 1 "Missing Pref" 0 "Not Missing Pref"
label values d1_missing d2_missing d3_missing d4_missing dmis
tab1 d1_missing d2_missing d3_missing d4_missing


foreach var in disc1_knowl disc1_freq {
	ttest `var', by(d1_missing)
	}


foreach var in disc2_knowl disc2_freq {
	ttest `var', by(d2_missing)
	}
	

foreach var in disc3_knowl disc3_freq {
	ttest `var', by(d3_missing)
	}


foreach var in disc4_knowl disc4_freq {
	ttest `var', by(d4_missing)
	}

/****************************************
*****************************************
		2006 ANES
*****************************************
****************************************/	


clear
do "Data Cleaning - 2006 ANES.do"
set more off

	foreach var in V06P603x V06P608x V06P613x {
		tab `var'
		}
	
	*7 = 0ther; 8 = don't know*
	
recode V06P603x V06P608x V06P613x (7 8 = 1) (else=0), gen(d1_missing d2_missing d3_missing)
label def dmis 1 "Missing Pref" 0 "Not Missing Pref"
label values d1_missing d2_missing d3_missing  dmis
tab1 d1_missing d2_missing d3_missing 

foreach var in disc1_interest cut_V06P591x disc1_gen close1 {
	ttest `var' , by(d1_missing)
	}
	
foreach var in disc2_interest cut_V06P593x disc2_gen close2 {
	ttest `var' , by(d1_missing)
	}

foreach var in disc3_interest cut_V06P595x disc3_gen close3 {
	ttest `var' , by(d1_missing)
	}


clear

/****************************************
*****************************************
		2008-9 ANES
*****************************************
****************************************/	

clear
do "Data Cleaning - 2008 Panel.do"
set more off

foreach var in W9ZD12_1 W9ZD12_2 W9ZD12_3 W9ZD13_2 W9ZD12_3 W9ZD13_3  {
		tab `var'  if W9FLAG == 1 & W9ZD1 == 1 
		}
		
tab1 d1_pid d2_pid d3_pid if W9ZD1 == 1


gen d1_missing = . 
	replace d1_missing = 1 if d1_pid == . & numgiven >=1 & W9ZD1 == 1
	replace d1_missing = 0 if d1_pid !=.
	
gen d2_missing = . 
	replace d2_missing = 1 if d2_pid == . & numgiven >=2 & W9ZD1 == 1
	replace d2_missing = 0 if d2_pid !=.
	
gen d3_missing = . 
	replace d3_missing = 1 if d3_pid == . & numgiven >=3 & W9ZD1 == 1
	replace d3_missing = 0 if d3_pid !=.

	label def dmis 1 "Missing Pref" 0 "Not Missing Pref"
label values d1_missing d2_missing d3_missing  dmis
tab1 d1_missing d2_missing d3_missing 

	
foreach var in interestd1 gendiff1 close1 {
	ttest `var', by(d1_missing)
	}
	
	
	foreach var in interestd2 gendiff2 close2 {
	ttest `var', by(d2_missing)
	}
	
	foreach var in interestd3 gendiff3  close3 {
	ttest `var', by(d3_missing)
	}
	
	



/*********************************************************
**********************************************************
	Just Partisan Pairs vs All Pairs
	
	Note: these analyses use an alternative
	version of the data cleaning files
	
	Original or Old refers to In-Text analyses
	where Independents and 3rd party supporters
	are part of the disagreement analysis, while 
	New refers to ones where these people are 
	expunged from the disagreement scale. 
**********************************************************
*********************************************************/


/****************************************
*****************************************
		1992 CNEP 
*****************************************
****************************************/

clear
do "Data Cleaning - Partisan Pair Analysis - 1992 CNEP.do"
set more off

eststo clear
/*Original*/
rename disagree_total disagree11
rename disagree_total_1 disagree_total 

eststo: ologit retro i.partisan##c.disagree_total numgiven disc_knowl news_att age educ ///
	income i.gender i.race i.employed i.marital 
	
	margins, dydx(disagree_total) by(partisan) predict(outcome(3))
	margins partisan, at(disagree_total=(-5(1)5)) predict(outcome(3)) saving(eval_1992_original, replace)


/*New*/
rename disagree_total disagree_total_1
rename disagree11 disagree_total 


eststo: ologit retro i.partisan##c.disagree_total numgiven disc_knowl news_att age educ ///
	income i.gender i.race i.employed i.marital 
	
	margins, dydx(disagree_total) by(partisan) predict(outcome(3))
	margins partisan, at(disagree_total=(-5(1)5)) predict(outcome(3)) saving(eval_1992_justp, replace)


/*Figure*/
		
combomarginsplot  eval_1992_original eval_1992_justp, scheme(plotplainblind)  by(partisan) ///
		byopts(title("2000 ANES: Evaluations", size(medsmall))) labels("Original Measure" "New Measure (Just Partisan Pairs)")  legend(rows(1)) xtitle(, size(small)) ytitle("")

graph save "1992 Evals - partisan pairs comp", replace
graph export "1992 ANES Evals - partisan pairs comp.png", replace



/*Table*/
esttab using TABLE_1992EVAL_MODEL_PPAIRS.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("Original" "Partisan Pairs Only") addnotes("Analyses are weighted: V000002a") pr2 aic bic ///
			title({\b Table O.} "Disagreement and Econ Evals, 1992 CNEP: Comparing Measures")
		

/****************************************
*****************************************
		2000 ANES
*****************************************
****************************************/

clear
do "Data Cleaning - Partisan Pair Analysis - 2000 ANES.do"
set more off

/*******Knowledge********/
	
eststo clear

rename disagree_total disagree11
rename disagree_total_1 disagree_total 

eststo: logit def_knowl i.partisan##c.disagree_total names1 disc_knowl interest i.gender i.race ///
	i.marital age educ income nfc1 evaluate1 [pweight = V000002a]
		
		margins, dydx(disagree_total) by(partisan)
		margins partisan, at(disagree_total=(-4(1)4)) saving(knowl_2000_all, replace)

rename disagree_total disagree_total_1
rename disagree11 disagree_total 

	
eststo: logit def_knowl i.partisan##c.disagree_total names1 disc_knowl interest i.gender i.race ///
	i.marital age educ income nfc1 evaluate1 [pweight = V000002a]
		
		margins, dydx(disagree_total) by(partisan)
		margins partisan, at(disagree_total=(-4(1)4)) saving(knowl_2000_justp, replace)
		

	
/*Figure*/

combomarginsplot  knowl_2000_all knowl_2000_justp, scheme(plotplainblind)  by(partisan) ///
		byopts(title("2000 ANES: Knowledge", size(medsmall))) labels("Original Measure" "New Measure (Just Partisan Pairs)")  legend(rows(1)) xtitle(, size(small)) ytitle("")

graph save "2000 ANES Knowledge - partisan pairs comp", replace
graph export "2000 ANES Knowledge - partisan pairs comp.png", replace

		
/*Table*/
esttab using TABLE_2000KNOWL_MODEL_PPAIRS.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("Old" "Partisan Pairs Only") addnotes("Analyses are weighted: V000002a") pr2 aic bic ///
			title({\b Table O.} "Disagreement and Deficit Knowledge, 2000 ANES: Comparing Measures")
			
			
eststo clear

/****************************************
*****************************************
		2002 ANES
*****************************************
****************************************/

clear
do "Data Cleaning - Partisan Pair Analysis - 2002 ANES.do"
set more off

eststo clear
/*Old*/

rename disagree_total disagree11
rename disagree_total_1 disagree_total 

eststo: ologit retro2002_3 i.partisan2000##c.disagree_total names1 disc_knowl ///
	follow age2002 educ income2002 i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight=WT02PRE]
		
	margins, dydx(disagree_total) by(partisan2000) predict(outcome(3))
	margins partisan2000, at(disagree_total=(-4(1)4)) predict(outcome(3)) saving(eval_2002_original, replace)

/*New*/
	
rename disagree_total disagree_total_1
rename disagree11 disagree_total 

eststo: ologit retro2002_3 i.partisan2000##c.disagree_total names1 disc_knowl ///
	follow age2002 educ income2002 i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight=WT02PRE]
		
	margins, dydx(disagree_total) by(partisan2000) predict(outcome(3))
	margins partisan2000, at(disagree_total=(-4(1)4)) predict(outcome(3)) saving(eval_2002_justp, replace)
	
	
/*Figure*/
		
combomarginsplot  eval_2002_original eval_2002_justp, scheme(plotplainblind)  by(partisan2000) ///
		byopts(title("2002 ANES: Evaluations", size(medsmall))) labels("Original Measure" "New Measure (Just Partisan Pairs)")  legend(rows(1)) xtitle(, size(small)) ytitle("")

graph save "2002 ANES Evals - partisan pairs comp", replace
graph export "2002 ANES Evals - partisan pairs comp.png", replace


/*Table*/
esttab using TABLE_2002EVAL_MODEL_PPAIRS.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("Original" "Partisan Pairs Only") addnotes("Analyses are weighted: V000002a") pr2 aic bic ///
			title({\b Table O.} "Disagreement and Econ Evals, 2002 ANES: Comparing Measures")


/****************************************
*****************************************
		2006 ANES
*****************************************
****************************************/

clear
do "Data Cleaning - Partisan Pair Analysis - 2006 ANES"
set more off


eststo clear
/*original*/
rename disagree_total disagree11
rename disagree_total_1 disagree_total 


eststo: ologit retro i.partisan2004##c.disagree_total names disc_interest follow04 ///
	age educ income i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight = V06P002]	
	
	margins, dydx(disagree_total) by(partisan2004) predict(outcome(3))
	margins partisan2004, at(disagree_total=(-3(1)3)) predict(outcome(3)) saving(eval_2006_original, replace)


/*New*/
	
rename disagree_total disagree_total_1
rename disagree11 disagree_total 

eststo: ologit retro i.partisan2004##c.disagree_total names disc_interest follow04 ///
	age educ income i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight = V06P002]	
	
	margins, dydx(disagree_total) by(partisan2004) predict(outcome(3))
	margins partisan2004, at(disagree_total=(-3(1)3)) predict(outcome(3)) saving(eval_2006_justp, replace)


/*Figure*/
		
combomarginsplot  eval_2006_original eval_2006_justp, scheme(plotplainblind)  by(partisan2004) ///
		byopts(title("2006 ANES: Evaluations", size(medsmall))) labels("Original Measure" "New Measure (Just Partisan Pairs)")  legend(rows(1)) xtitle(, size(small)) ytitle("")

graph save "2006 ANES Evals - partisan pairs comp", replace
graph export "2006 ANES Evals - partisan pairs comp.png", replace


/*Table*/
esttab using TABLE_2006EVAL_MODEL_PPAIRS.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("Original" "Partisan Pairs Only") addnotes("Analyses are weighted: V000002a") pr2 aic bic ///
			title({\b Table O.} "Disagreement and Econ Evals, 2002 ANES: Comparing Measures")
			

/****************************************
*****************************************
		2008-9 ANES
*****************************************
****************************************/



clear
do "Data Cleaning - Partisan Pair Analysis - 2008 ANES.do"
set more off


/******Knowledge*******/

/***May****/

eststo clear
/*Old*/

rename disagree_total disagree11
rename disagree_total_1 disagree_total 

eststo: logit def_knowl17 i.partisan_9rev##c.disagree_total numgiven1 network_interest interest_w9 i.gender i.race i.marital ///
	age educ income nfc1 evaluate1  [pweight= WGTPP17]
	
		margins, dydx(disagree_total) by(partisan_9rev)
		margins partisan_9rev, at(disagree_total=(-3(1)3)) saving(knowl_may_original, replace)

/*New*/
	
rename disagree_total disagree_total_1
rename disagree11 disagree_total 

	eststo: logit def_knowl17 i.partisan_9rev##c.disagree_total numgiven1 network_interest interest_w9 i.gender i.race i.marital ///
	age educ income nfc1 evaluate1  [pweight= WGTPP17]
	
		margins, dydx(disagree_total) by(partisan_9rev)
		margins partisan_9rev, at(disagree_total=(-3(1)3)) saving(knowl_may_justp, replace)
		

/*Figure*/
		
combomarginsplot  knowl_may_original knowl_may_justp, scheme(plotplainblind)  by(partisan_9rev) ///
		byopts(title("May 2009 ANES: Knowledge", size(medsmall))) labels("Original Measure" "New Measure (Just Partisan Pairs)")  legend(rows(1)) xtitle(, size(small)) ytitle("")

graph save "May ANES Knowl - partisan pairs comp", replace
graph export "May ANES Knowl - partisan pairs comp.png", replace


/*Table*/
esttab using TABLE_MAYKNOWL_MODEL_PPAIRS.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("Original" "Partisan Pairs Only") addnotes("Analyses are weighted: V000002a") pr2 aic bic ///
			title({\b Table O.} "Disagreement and Knowledge, May 2009 ANES: Comparing Measures")
			


/***July***/
eststo clear

/*old*/
rename disagree_total disagree11
rename disagree_total_1 disagree_total 


	eststo: logit def_knowl19 i.partisan_9rev##c.disagree_total numgiven1 network_interest ///
		interest_w9 i.gender i.race i.marital age educ income nfc1 evaluate1 [pweight= WGTPP19]

		margins, dydx(disagree_total) by(partisan_9rev)
		margins partisan_9rev, at(disagree_total=(-3(1)3)) saving(knowl_july_original, replace)
		
/*new*/
rename disagree_total disagree_total_1
rename disagree11 disagree_total 
		
	eststo: logit def_knowl19 i.partisan_9rev##c.disagree_total numgiven1 network_interest ///
		interest_w9 i.gender i.race i.marital age educ income nfc1 evaluate1 [pweight= WGTPP19]

		margins, dydx(disagree_total) by(partisan_9rev)
		margins partisan_9rev, at(disagree_total=(-3(1)3)) saving(knowl_july_justp, replace)
	
/*Figure*/
	combomarginsplot  knowl_july_original knowl_july_justp, scheme(plotplainblind)  by(partisan_9rev) ///
		byopts(title("July 2009 ANES: Knowledge", size(medsmall))) labels("Original Measure" "New Measure (Just Partisan Pairs)")  legend(rows(1)) xtitle(, size(small)) ytitle("")

graph save "July ANES Knowl - partisan pairs comp", replace
graph export "July ANES Knowl - partisan pairs comp.png", replace


/*Table*/
esttab using TABLE_JULYKNOWL_MODEL_PPAIRS.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("Original" "Partisan Pairs Only") addnotes("Analyses are weighted: V000002a") pr2 aic bic ///
			title({\b Table O.} "Disagreement and Knowledge, July 2009 ANES: Comparing Measures")

		
		
/*****July: incorrect in may****/
eststo clear
/*old*/
rename disagree_total disagree11
rename disagree_total_1 disagree_total 


	eststo: logit def_knowl19 i.partisan_9rev##c.disagree_total numgiven1 network_interest ///
		interest_w9 i.gender i.race i.marital age educ income nfc1 evaluate1  i.def_knowl17 [pweight= WGTPP19]

		margins, dydx(disagree_total) by(partisan_9rev) at(def_knowl17=(0))
		margins partisan_9rev, at(disagree_total=(-3(1)3)  def_knowl17=(0)) saving(knowl_july_original_incor, replace)
		
		
/*new*/
rename disagree_total disagree_total_1
rename disagree11 disagree_total 
		
	eststo: logit def_knowl19 i.partisan_9rev##c.disagree_total numgiven1 network_interest ///
		interest_w9 i.gender i.race i.marital age educ income nfc1 evaluate1 i.def_knowl17 [pweight= WGTPP19]

		margins, dydx(disagree_total) by(partisan_9rev) at(def_knowl17=(0))
		margins partisan_9rev, at(disagree_total=(-3(1)3)  def_knowl17=(0)) saving(knowl_july_justp_incor, replace)
		
		
/*Figure*/
	combomarginsplot  knowl_july_original_incor knowl_july_justp_incor, scheme(plotplainblind)  by(partisan_9rev) ///
		byopts(title("July 2009 ANES (Incorrect in May): Knowledge", size(medsmall))) labels("Original Measure" "New Measure (Just Partisan Pairs)")  legend(rows(1)) xtitle(, size(small)) ytitle("")

graph save "July ANES Knowl (incor) - partisan pairs comp", replace
graph export "July ANES Knowl (incor) - partisan pairs comp.png", replace


/*Table*/
esttab using TABLE_JULYINCORKNOWL_MODEL_PPAIRS.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("Original" "Partisan Pairs Only") addnotes("Analyses are weighted: V000002a") pr2 aic bic ///
			title({\b Table O.} "Disagreement and Knowledge, July 2009 ANES (Incor. in May): Comparing Measures")
			
	
		

/***********Evaluations********/
		
/******May*****/
eststo clear

/*Old*/
	
rename disagree_total disagree11
rename disagree_total_1 disagree_total 

eststo: ologit w17_retro i.partisan_9rev##c.disagree_total c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP17]
	
	margins, dydx(disagree_total) by(partisan_9rev) predict(outcome(3))
	margins partisan_9rev, at(disagree_total=(-3(1)3)) predict(outcome(3)) saving(eval_may_original, replace)
	
/*New*/

rename disagree_total disagree_total_1
rename disagree11 disagree_total 
		
		
eststo: ologit w17_retro i.partisan_9rev##c.disagree_total c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP17]
	
	margins, dydx(disagree_total) by(partisan_9rev) predict(outcome(3))
	margins partisan_9rev, at(disagree_total=(-3(1)3)) predict(outcome(3)) saving(eval_may_justp, replace)
	
	
/*Figure*/
	combomarginsplot  eval_may_original eval_may_justp,  scheme(plotplainblind)  by(partisan_9rev) ///
		byopts(title("May 2009 ANES: Evaluations", size(medsmall))) labels("Original Measure" "New Measure (Just Partisan Pairs)")  legend(rows(1)) xtitle(, size(small)) ytitle("")

graph save "May ANES Eval - partisan pairs comp", replace
graph export "May ANES Eval - partisan pairs comp.png", replace


/*Table*/
esttab using TABLE_MAYEVAL_MODEL_PPAIRS.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("Original" "Partisan Pairs Only") addnotes("Analyses are weighted: V000002a") pr2 aic bic ///
			title({\b Table O.} "Disagreement and Evaluations, May 2009 ANES: Comparing Measures")
			

			
/*******July******/
eststo clear

/*Old*/

rename disagree_total disagree11
rename disagree_total_1 disagree_total 

eststo: ologit w19_retro i.partisan_9rev##c.disagree_total c.numgiven network_interest interest_w9 ///
		age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP19]
	
	margins, dydx(disagree_total) by(partisan_9rev) predict(outcome(3))
	margins partisan_9rev, at(disagree_total=(-3(1)3)) predict(outcome(3)) saving(eval_july_original, replace)
	
/*New*/

rename disagree_total disagree_total_1
rename disagree11 disagree_total 
	
eststo: ologit w19_retro i.partisan_9rev##c.disagree_total c.numgiven network_interest interest_w9 ///
		age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP19]
	
		margins, dydx(disagree_total) by(partisan_9rev) predict(outcome(3))
	margins partisan_9rev, at(disagree_total=(-3(1)3)) predict(outcome(3)) saving(eval_july_justp, replace)
	
		
/*Figure*/
	combomarginsplot  eval_july_original eval_july_justp,  scheme(plotplainblind)  by(partisan_9rev) ///
		byopts(title("July 2009 ANES: Evaluations", size(medsmall))) labels("Original Measure" "New Measure (Just Partisan Pairs)")  legend(rows(1)) xtitle(, size(small)) ytitle("")

graph save "July ANES Eval - partisan pairs comp", replace
graph export "July ANES Eval - partisan pairs comp.png", replace


/*Table*/
esttab using TABLE_JULYEVAL_MODEL_PPAIRS.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("Original" "Partisan Pairs Only") addnotes("Analyses are weighted: V000002a") pr2 aic bic ///
			title({\b Table O.} "Disagreement and Evaluations, July 2009 ANES: Comparing Measures")
			

			




/*********************************************************
**********************************************************\
	2006 and 2008: Treating Leaning Ind. as
	Partisans vs. as Independents
**********************************************************
*********************************************************/


/****************************************
*****************************************
		2006 ANES
*****************************************
****************************************/	


clear
do "Data Cleaning - 2006 ANES.do"
set more off

/*Leaners as Partisans: disagree_total
Leaners as Independents: disagree_total_nl

mean total: -1.29 (1.54)
total_nl: -0.65 (1.74)
*/

eststo clear
/*Original: Leaners as Partisans*/
eststo: ologit retro i.partisan2004##c.disagree_total names disc_interest follow04 ///
	age educ income i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight = V06P002]	
	
	margins, dydx(disagree_total) by(partisan2004) predict(outcome(3))
	margins partisan2004, at(disagree_total=(-3(1)3)) predict(outcome(3)) saving(eval_2004_plean, replace)
	
rename disagree_total disagree_orig
rename disagree_total_nl disagree_total

eststo: ologit retro i.partisan2004##c.disagree_total names disc_interest follow04 ///
	age educ income i.gender i.race i.employed i.marital nfc1 evaluate1 [pweight = V06P002]	
	
	margins, dydx(disagree_total) by(partisan2004) predict(outcome(3))
	margins partisan2004, at(disagree_total=(-3(1)3)) predict(outcome(3)) saving(eval_2004_pnlean, replace)
		
/*Figure*/
		
combomarginsplot  eval_2004_plean eval_2004_pnlean, scheme(plotplainblind)  by(partisan2004) ///
		byopts(title("2006 ANES: Evaluations", size(medsmall))) labels("Leaners as Partisans" "Leaners as Independent")  legend(rows(1)) xtitle(, size(small)) ytitle("")

graph save "2006 Evals - leaners vs noleaners", replace
graph export "2006 Evals - leaners vs noleaners.png", replace


/*Table*/
esttab using TABLE_2006EVAL_MODEL_PLEAN.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("Leaners as Partisan" "Leaners as Ind.")  pr2 aic bic ///
			title({\b Table O.} "Disagreement and Econ Evals, 2006 ANES: Comparing Measures")
		


/****************************************
*****************************************
		2008-9 ANES
*****************************************
****************************************/	


clear
do "Data Cleaning - 2008 Panel.do"
set more off


/***Creating disagremeent with non-partisan pairs included***/

*Agreement
	*1 = Dem/Dem, Ind/Ind, Rep/Rep
	*0 = Dem/Rep, Dem/Something Else, Dem/Ind
	*0= Rep/Dem,. Rep/Something Else, rep/Ind
	*0 = Ind/Dem, Ind/Rep
	gen d1_agree1 = . 
	replace d1_agree1 = 1 if pid_39 == 1 & W9ZD12_1 == 1
	replace d1_agree1 = 1 if pid_39 == 2 & W9ZD12_1 == 2
	replace d1_agree1 = 1 if pid_39 == 3 & W9ZD12_1 == 3
	replace d1_agree1 = 0 if pid_39 == 1 & W9ZD12_1 == 2 
	replace d1_agree1 = 0 if pid_39 == 1 & W9ZD12_1 == 3
	replace d1_agree1 = 0 if pid_39 == 1 & W9ZD12_1 == 4
	replace d1_agree1 = 0 if pid_39 == 2 & W9ZD12_1 == 1
	replace d1_agree1 = 0 if pid_39 == 2 & W9ZD12_1 == 3
	replace d1_agree1 = 0 if pid_39 == 2 & W9ZD12_1 == 4
	replace d1_agree1 = 0 if pid_39 == 3 & W9ZD12_1 == 1
	replace d1_agree1 = 0 if pid_39 == 3 & W9ZD12_1 == 2
	replace d1_agree1 = 1 if pid_39 == 1 & W9ZD13_1 == 2
	replace d1_agree1 = 1 if pid_39 == 2 & W9ZD13_1 == 1
	replace d1_agree1 = 1 if pid_39 == 3 & W9ZD13_1 == 3
	replace d1_agree1 = 0 if pid_39 == 1 & W9ZD13_1 == 1 
	replace d1_agree1 = 0 if pid_39 == 1 & W9ZD13_1 == 3
	replace d1_agree1 = 0 if pid_39 == 1 & W9ZD13_1 == 4
	replace d1_agree1 = 0 if pid_39 == 2 & W9ZD13_1 == 2
	replace d1_agree1 = 0 if pid_39 == 2 & W9ZD13_1 == 3
	replace d1_agree1 = 0 if pid_39 == 2 & W9ZD13_1 == 4
	replace d1_agree1 = 0 if pid_39 == 3 & W9ZD13_1 == 1
	replace d1_agree1 = 0 if pid_39 == 3 & W9ZD13_1 == 2
	label var d1_agree1 "D1 Agree? (old)"
	label values d1_agree1 ag
	

	gen d2_agree1 = . 
	replace d2_agree1 = 1 if pid_39 == 1  & W9ZD12_2 == 1
	replace d2_agree1 = 1 if pid_39 == 2 & W9ZD12_2 == 2
	replace d2_agree1 = 1 if pid_39 == 3 & W9ZD12_2 == 3
	replace d2_agree1 = 0 if pid_39 == 1  & W9ZD12_2 == 2 
	replace d2_agree1 = 0 if pid_39 == 1  & W9ZD12_2 == 3
	replace d2_agree1 = 0 if pid_39 == 1  & W9ZD12_2 == 4
	replace d2_agree1 = 0 if pid_39 == 2 & W9ZD12_2 == 1
	replace d2_agree1 = 0 if pid_39 == 2 & W9ZD12_2 == 3
	replace d2_agree1 = 0 if pid_39 == 2 & W9ZD12_2 == 4
	replace d2_agree1 = 0 if pid_39 == 3 & W9ZD12_2 == 1
	replace d2_agree1 = 0 if pid_39 == 3 & W9ZD12_2 == 2
	replace d2_agree1 = 1 if pid_39 == 1  & W9ZD13_2 == 2
	replace d2_agree1 = 1 if pid_39 == 2 & W9ZD13_2 == 1
	replace d2_agree1 = 1 if pid_39 == 3 & W9ZD13_2 == 3
	replace d2_agree1 = 0 if pid_39 == 1  & W9ZD13_2 == 1 
	replace d2_agree1 = 0 if pid_39 == 1  & W9ZD13_2 == 3
	replace d2_agree1 = 0 if pid_39 == 1  & W9ZD13_2 == 4
	replace d2_agree1 = 0 if pid_39 == 2 & W9ZD13_2 == 2
	replace d2_agree1 = 0 if pid_39 == 2 & W9ZD13_2 == 3
	replace d2_agree1 = 0 if pid_39 == 2 & W9ZD13_2 == 4
	replace d2_agree1 = 0 if pid_39 == 3 & W9ZD13_2 == 1
	replace d2_agree1 = 0 if pid_39 == 3 & W9ZD13_2 == 2
	label var d2_agree1 "D2 Agree? old"
	label values d2_agree1 ag
	
	gen d3_agree1 = . 
	replace d3_agree1 = 1 if pid_39 == 1  & W9ZD12_3 == 1
	replace d3_agree1 = 1 if pid_39 == 2 & W9ZD12_3 == 2
	replace d3_agree1 = 1 if pid_39 == 3 & W9ZD12_3 == 3
	replace d3_agree1 = 0 if pid_39 == 1  & W9ZD12_3 == 2 
	replace d3_agree1 = 0 if pid_39 == 1  & W9ZD12_3 == 3
	replace d3_agree1 = 0 if pid_39 == 1  & W9ZD12_3 == 4
	replace d3_agree1 = 0 if pid_39 == 2 & W9ZD12_3 == 1
	replace d3_agree1 = 0 if pid_39 == 2 & W9ZD12_3 == 3
	replace d3_agree1 = 0 if pid_39 == 2 & W9ZD12_3 == 4
	replace d3_agree1 = 0 if pid_39 == 3 & W9ZD12_3 == 1
	replace d3_agree1 = 0 if pid_39 == 3 & W9ZD12_3 == 2
	replace d3_agree1 = 1 if pid_39 == 1  & W9ZD13_3 == 2
	replace d3_agree1 = 1 if pid_39 == 2 & W9ZD13_3 == 1
	replace d3_agree1 = 1 if pid_39 == 3 & W9ZD13_3 == 3
	replace d3_agree1 = 0 if pid_39 == 1  & W9ZD13_3 == 1
	replace d3_agree1 = 0 if pid_39 == 1  & W9ZD13_3 == 3
	replace d3_agree1 = 0 if pid_39 == 1  & W9ZD13_3 == 4
	replace d3_agree1 = 0 if pid_39 == 2 & W9ZD13_3 == 2
	replace d3_agree1 = 0 if pid_39 == 2 & W9ZD13_3 == 3
	replace d3_agree1 = 0 if pid_39 == 2 & W9ZD13_3 == 4
	replace d3_agree1 = 0 if pid_39 == 3 & W9ZD13_3 == 1
	replace d3_agree1 = 0 if pid_39 == 3 & W9ZD13_3 == 2
	label var d3_agree1 "D3 Agree? (old)"
	label values d3_agree1 ag
	

*Disagreement
	*0 = Dem/Dem, Ind/Ind, Rep/Rep
	*1 = Dem/Rep, Dem/Something Else, Dem/Ind
	*1= Rep/Dem,. Rep/Something Else, rep/Ind
	*1 = Ind/Dem, Ind/Rep

	omscore d1_agree1
	rename rr_d1_agree1 d1_disagree1
	label var d1_disagree1 "D1 Disagree? (old)"
	label values d1_disagree1 disag1
	
	omscore d2_agree1
	rename rr_d2_agree1 d2_disagree1		
	label var d2_disagree1 "D2 Agree? (old)"
	label values d2_disagree1 disag1
	
	omscore d3_agree1
	rename rr_d3_agree1 d3_disagree1
	label var d3_disagree1 "D3 Agree? (old)"
	label values d3_disagree1 disag1
		
		
*Summary and Average
	*Summary Agreement
		egen pid_agree1 = rowtotal(d1_agree1 d2_agree1 d3_agree1), missing
	*Disagreement
		egen pid_disagree1 = rowtotal(d1_disagree1 d2_disagree1 d3_disagree1), missing
	
	*Summary Scale
			*See Lupton and Thornton: Exposure = D - A
			gen disagree_total1 = pid_disagree1 - pid_agree1
			label var disagree_total1 "Network Disagreement (old)"
				
	summ disagree_total disagree_total1, detail
	pwcorr disagree_total disagree_total1
		
		summ disagree_total disagree_total1 if pid_29 !=., detail
	pwcorr disagree_total disagree_total1 if pid_29 !=.
	

	
/****************Replicating***************/
	
/********Knowledge*********/
rename partisan_9rev partisan

*****May*
eststo clear

*lean as independents*
rename disagree_total1 disagree_common

eststo: logit def_knowl17 i.partisan##c.disagree_common numgiven1 network_interest interest_w9 i.gender i.race i.marital ///
	age educ income nfc1 evaluate1  [pweight= WGTPP17]
	
	margins, dydx(disagree_common) by(partisan)
	margins partisan, at(disagree_common=(-3(1)3)) saving(fixed_knowl_old_independents, replace)

rename disagree_common disagree_total1
rename disagree_total disagree_common

*lean as partisans*	
eststo: logit def_knowl17 i.partisan##c.disagree_common numgiven1 network_interest interest_w9 i.gender i.race i.marital ///
	age educ income nfc1 evaluate1  [pweight= WGTPP17]
	
	margins, dydx(disagree_common) by(partisan)

	margins partisan, at(disagree_common=(-3(1)3)) saving(fixed_knowl_new_partisans, replace)	
	
rename disagree_common disagree_total
rename disagree_total1 disagree_common



*********July******
*old*
eststo: logit def_knowl19 i.partisan##c.disagree_common numgiven1 network_interest interest_w9 i.gender i.race i.marital age educ income nfc1 evaluate1 [pweight= WGTPP19]
	
	margins, dydx(disagree_common) by(partisan)
	margins partisan, at(disagree_common=(-3(1)3)) saving(fixed_knowl_old_july, replace)	

rename disagree_common disagree_total1
rename disagree_total disagree_common

*New*
	
eststo: logit def_knowl19 i.partisan##c.disagree_common numgiven1 network_interest interest_w9 i.gender i.race i.marital age educ income nfc1 evaluate1 [pweight= WGTPP19]
	
	margins, dydx(disagree_common) by(partisan)
	margins partisan, at(disagree_common=(-3(1)3)) saving(fixed_knowl_new_july, replace)	

rename disagree_common disagree_total
rename disagree_total1 disagree_common	
	
**********July: Correct*********
*Old*
eststo: logit def_knowl19 i.partisan##c.disagree_common i.def_knowl17 numgiven1 network_interest interest_w9 i.gender i.race i.marital age educ income nfc1 evaluate1 [pweight= WGTPP19]
	margins, dydx(disagree_common) by(partisan) at(def_knowl17=(0))
	
	margins partisan, at(disagree_common=(-3(1)3) def_knowl17=(0)) saving(fixed_knowl_old_julyC, replace)
	
	
*New*
rename disagree_common disagree_total1
rename disagree_total disagree_common	

eststo: logit def_knowl19 i.partisan##c.disagree_common i.def_knowl17 numgiven1 network_interest interest_w9 i.gender i.race i.marital age educ income nfc1 evaluate1 [pweight= WGTPP19]
	margins, dydx(disagree_common) by(partisan) at(def_knowl17=(0))
	
	margins partisan, at(disagree_common=(-3(1)3) def_knowl17=(0)) saving(fixed_knowl_new_julyC, replace)
	
rename disagree_common disagree_total
	
		
/*Table*/
esttab using TABLE_2008PAINDL_MODEL.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("As Ind." "As Partisan" "As Ind." "As Partisan" "As Ind." "As Partisan") ///
			pr2 aic bic ///
			title({\b Table O.} "2008 Panel - Measures with and without leaners as independents")

eststo clear	
	
	
/***Figures****/

combomarginsplot fixed_knowl_old_independents fixed_knowl_new_partisans, scheme(plotplainblind) by(partisan)  ///
	legend(rows(1)) labels("Leaner as Ind." "Leaner as Partisan") ///
	byopts(title("May 2008: Knowledge"))  xtitle("Disagreement") ytitle("Pr(Correct)")

graph save "2008PA - may fixed comp", replace
graph export "2008PA - may fixed comp.png", replace


combomarginsplot fixed_knowl_old_july fixed_knowl_new_july, scheme(plotplainblind) by(partisan)  ///
	legend(rows(1)) labels("Leaner as Ind." "Leaner as Partisan") ///
	byopts(title("July 2008: Knowledge"))  xtitle("Disagreement") ytitle("Pr(Correct)")

graph save "2008PA - july fixed comp", replace
graph export "2008PA - july fixed comp.png", replace

	
combomarginsplot fixed_knowl_old_julyC fixed_knowl_new_julyC, scheme(plotplainblind) by(partisan)  ///
	legend(rows(1)) labels("Leaner as Ind." "Leaner as Partisan") ///
	byopts(title("July 2008: Knowledge (Wrong in May)"))  xtitle("Disagreement") ytitle("Pr(Correct)")

graph save "2008PA - july (wrong) fixed comp", replace
graph export "2008PA - july (wrong) fixed comp.png", replace


	
/*******************************Evaluations*************************/
eststo clear
**********May*******
rename partisan partisan_9rev

*Old*

rename disagree_total1 disagree_common

eststo: ologit w17_retro i.partisan_9rev##c.disagree_common c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP17]
	
		margins, dydx(disagree_common) by(partisan_9rev) predict(outcome(3))
		margins partisan_9rev, at(disagree_common=(-3(1)3)) predict(outcome(3)) saving(fixed_eval_may_old, replace)

rename disagree_common disagree_total1
rename disagree_total disagree_common

*New*
eststo: ologit w17_retro i.partisan_9rev##c.disagree_common c.numgiven network_interest interest_w9 	///
	age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP17]
	
		margins, dydx(disagree_common) by(partisan_9rev) predict(outcome(3))
		margins partisan_9rev, at(disagree_common=(-3(1)3)) predict(outcome(3)) saving(fixed_eval_may_new, replace)
		
			
/****July********/
rename disagree_common disagree_total
rename disagree_total1 disagree_common	
			
*Old*
		
eststo: ologit w19_retro i.partisan_9rev##c.disagree_common c.numgiven network_interest interest_w9 ///
		age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP19]		
			
		margins, dydx(disagree_common) by(partisan_9rev) predict(outcome(3))
		margins partisan_9rev, at(disagree_common=(-3(1)3)) predict(outcome(3)) saving(fixed_eval_july_old, replace)
		
*New*
rename disagree_common disagree_total1
rename disagree_total disagree_common

eststo: ologit w19_retro i.partisan_9rev##c.disagree_common c.numgiven network_interest interest_w9 ///
		age educ income i.gender i.race i.empl_w11a i.marital nfc1 evaluate1 [pweight= WGTPP19]		
			
		margins, dydx(disagree_common) by(partisan_9rev) predict(outcome(3))
		margins partisan_9rev, at(disagree_common=(-3(1)3)) predict(outcome(3)) saving(fixed_eval_july_new, replace)
	
rename disagree_common disagree_total

/****Table****/

esttab using TABLE_2008PAINDLEVAL_MODEL.rtf, onecell replace label se star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("As Ind." "As Partisan" "As Ind." "As Partisan") ///
			pr2 aic bic ///
			title({\b Table O.} "2008 Panel - Econ Evals - Measures with and without leaners as independents")

eststo clear	
	
	
/***Figures****/

combomarginsplot fixed_eval_may_old fixed_eval_may_new, legend(rows(1)) labels("Leaner as Ind." "Leaner as Partisan") ///
	byopts(title("May 2008: Evaluations"))  xtitle("Disagreement") ytitle("Pr('Better')") by(partisan_9rev) scheme(plotplainblind)

graph save "fixed - may - evals comp", replace
graph export "fixed - may - evals comp.png", replace
 

 
combomarginsplot fixed_eval_july_old fixed_eval_july_new, legend(rows(1)) labels("Leaner as Ind." "Learner as Partisan") ///
	byopts(title("July 2008: Evaluations"))  xtitle("Disagreement") ytitle("Pr('Better')") by(partisan_9rev) scheme(plotplainblind)

graph save "fixed - july - evals comp", replace
graph export "fixed - july - evals comp.png", replace
 
	
	


log close













